package com.fanco.learn_datastruct_leetcode.designpattern.visitor.demo2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author qiaowang 2022/2/21
 * 描述
 */
public class Computer implements ComputerPart{

    List<ComputerPart> computerParts = new ArrayList<>();

    public void attach (ComputerPart computerPart) {
        computerParts.add(computerPart);
    }

    public void detach (ComputerPart computerPart) {
        computerParts.remove(computerPart);
    }

    @Override
    public void accept(ComputerPartVisitor visitor) {
        for (ComputerPart computerPart : computerParts) {
            computerPart.accept(visitor);
        }
        visitor.visit(this);
    }
}
